extends Area2D

var fore_ground_map: TileMap
var displaying := false
var dispearing := false

func _ready() -> void:
	fore_ground_map = get_tree().get_first_node_in_group("foreground_map")
	area_entered.connect(on_area_entered)
	area_exited.connect(on_area_exited)

func _process(delta: float) -> void:
	if (displaying):
		fore_ground_map.modulate.a = lerpf(.2, fore_ground_map.modulate.a, pow(2, -10 * delta))
	if (dispearing):
		fore_ground_map.modulate.a = lerpf(1, fore_ground_map.modulate.a, pow(2, -10 * delta))

func on_area_entered(area2d):
	displaying = true

func on_area_exited(area2d):
	displaying = false
	dispearing = true
